﻿

using System;

namespace 循环语句练习
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //1 打印100-1000以内的水仙花数，不包括1000

            //for (int i = 100;i < 1000;i++)
            //{
            //    int g = i % 10;
            //    int s = i / 10 % 10;
            //    int b = i / 10 / 10 % 10;

            //    int n = b * b * b + s * s * s + g * g * g;

            //    if (n == i)
            //    {
            //        Console.WriteLine(i);
            //    }

            //}

            int n = 0;
            int num = 0;
            for (int b = 1; b < 10; b++)
            {
                for (int s = 0; s < 10; s++)
                {
                    for (int g = 0;g < 10;g++)
                    {
                        n = b * b * b + s * s * s + g * g * g;
                        num = b * 100 + s * 10 + g;

                        if (num == n) 
                        {
                            Console.WriteLine(num);
                        }
                    }
                }
            }
            Console.Read();

            //鸡兔同笼问题
            //数量一共30只，脚数量一共90根，请问鸡跟兔子各自有多少只

            for (int chicken = 0;chicken <= 30;chicken++) 
            {
                for(int rabbit = 0;rabbit <= 30;rabbit++)
                {
                    if(chicken + rabbit == 30 && chicken * 2 + rabbit * 4 == 90)
                    {
                        Console.WriteLine("鸡有{0}只，兔子有{1}只",chicken,rabbit);
                    }
                }
            }
            Console.Read();
        }
    }
}
